﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Windows.Controls.Ribbon;
using System.Collections.ObjectModel;

namespace DentistApplication
{
    /// <summary>
    /// Interaction logic for PatientFileWindow.xaml
    /// </summary>
    public partial class PatientFileWindow : RibbonWindow
    {
        public PatientFileWindow()
        {
            InitializeComponent();

            //Make some multiline text in labels
            la_file.Content = "Kartoteka \r\npacjenta";
            la_applast.Content = "Ostatnie wizyty \r\npacjenta";
            la_appnew.Content = "Umówione wizyty \r\npacjenta";

            //FillTheComboboxWithFields
            List<string> fields = PatientsHandler.getFieldsInPatientTable();
            fields.Remove("firstname");
            fields.Remove("lastname");
            fields.ForEach(x => boxCombo_other.Items.Add(x));
            boxCombo_other.SelectedIndex = 1;

          
        }

        ObservableCollection<Patient> _patientCollection = new ObservableCollection<Patient>();

        public ObservableCollection<Patient> patientCollection
        { get { return _patientCollection; } }

        #region RIBBON - Search for Patient

        private void list_patientsSearch_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ribTAB_showData.IsSelected = true;
        }

       
        private void box_searchPatient_TextChanged(object sender, TextChangedEventArgs e)
        {
            int minLen = 0;
            string name = box_SearchPatName.Text;
            string lastname = box_SearchPatLastName.Text;
            string other = box_other.Text;
            string otherType = boxCombo_other.SelectedValue.ToString();

            if (name.Length > minLen || lastname.Length > minLen || other.Length > minLen)
            {
                _patientCollection.Clear();
                List<Patient> lp = PatientsHandler.searchForPatients(name, lastname, otherType, other);
                lp.ForEach(x => _patientCollection.Add(x));

            }
        }
       

        #endregion

        #region RIBBON - Show Data
        private void ribbon_patientLastAppointments_MouseUp(object sender, MouseButtonEventArgs e)
        {

        }

        private void ribbon_patientNewAppointments_MouseUp(object sender, MouseButtonEventArgs e)
        {

        }
        private void ribbon_patientFile_MouseUp(object sender, MouseButtonEventArgs e)
        {
            try
            {
                PatientFile pf = new PatientFile(_patientCollection[list_patientsSearch.SelectedIndex]);
                pf.Show();
                this.Close();
            }
            catch{}
        }


        #endregion

        #region RIBBON - Options
        #endregion

        #region RIBBON - Help
        #endregion

    }
}
